AC_INIT(frogd,1.5.0)
AC_CONFIG_SRCDIR(src/frogd.c)
AC_CONFIG_AUX_DIR(config)
AC_PREFIX_DEFAULT(/usr/local/frogd/)

AC_CHECK_FUNCS([bzero])
AC_CHECK_FUNCS([pow])
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([string.h])
AC_CHECK_HEADERS([sys/file.h])
AC_CHECK_HEADERS([sys/ioctl.h])
AC_CHECK_HEADERS([unistd.h])
AC_FUNC_FORK


AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE

AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_PROG_INSTALL
AC_HEADER_STDC

# MySQL
AC_ARG_ENABLE([mysql],
        AC_HELP_STRING([--enable-mysql[=DIR]], [enable MySQL auth/reg/storage support (no)]),
        [ enable_mysql="$enableval" have_mysql=no  MYSQL_PREFIX="$enableval" ],
        [ enable_mysql=no           have_mysql=no ])

if test "x-$enable_mysql" != "x-no" ; then
        if test "$MYSQL_PREFIX" = "yes" ; then
                MYSQL_PREFIX=/usr
        fi

        AC_PATH_PROG(mysqlconfig,mysql_config,,[$MYSQL_PREFIX/bin:$PATH])
        if test [ -z "$mysqlconfig" ]
        then
                AC_MSG_ERROR([mysql_config executable not found: MySQL 5.0 or greater is required.])
        else
                AC_MSG_CHECKING(MySQL libraries)
                MYSQL_LIBS=`${mysqlconfig} --libs`
                AC_MSG_RESULT("$MYSQL_LIBS")

                AC_MSG_CHECKING(mysql includes)
                MYSQL_CFLAGS=`${mysqlconfig} --cflags`
                AC_MSG_RESULT("$MYSQL_CFLAGS")

                MYSQL_VERSION=`${mysqlconfig} --version`
                MYSQL_VERSION_MAJOR=${MYSQL_VERSION%%.*}
                if test $MYSQL_VERSION_MAJOR -lt 5 ; then
                        AC_MSG_ERROR([MySQL version 5.0 or greater required.])
                fi

                have_mysql=yes
                AC_DEFINE(ENABLE_MYSQL, 1, [Define to 1 if you want to use MySQL for storage.])
        fi
fi
AC_SUBST(MYSQL_CFLAGS)
AC_SUBST(MYSQL_LIBS)
AM_CONDITIONAL(ENABLE_MYSQL, [test "x-$have_mysql" = "x-yes"])


AC_OUTPUT([
    Makefile
    src/Makefile
    contrib/Makefile
    contrib/rrdtool/Makefile
    contrib/console/Makefile
    doc/Makefile    
])

